<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/3/20
 * Time: 10:33
 */

namespace App\Http\Controllers\MiniProgram;


use App\Http\Controllers\BaseController;
use App\Http\Logics\MiniProgram\AddressLogic;
use App\Http\Traits\AddressTrait;

class AddressController extends BaseController
{
    use AddressTrait;

    /**
     * @SWG\Get(
     *     path="/address/list",
     *     tags={"Address"},
     *     description="获取地址列表",
     *     operationId="getAddressList",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="is_default",
     *         in="query",
     *         description="是否默认地址",
     *         required=false,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function getAddressList()
    {
        $loginSession = $this->loginSession;
        $is_default = $this->is_default;
        $data = [
            'loginSession' => $loginSession,
            'is_default' => $is_default
        ];
        $response = AddressLogic::getAddressList($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Post(
     *     path="/address/create",
     *     tags={"Address"},
     *     description="创建地址",
     *     operationId="createAddress",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="username",
     *         in="query",
     *         description="收货人",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="postalcode",
     *         in="query",
     *         description="邮编",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="province",
     *         in="query",
     *         description="省",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="city",
     *         in="query",
     *         description="市",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="district",
     *         in="query",
     *         description="区",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="detail_info",
     *         in="query",
     *         description="详细地址",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="nationalcode",
     *         in="query",
     *         description="国家码",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="mobile",
     *         in="query",
     *         description="联系方式",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function createAddress()
    {
        $loginSession = $this->loginSession;
        $username = $this->username;
        $postalcode = $this->postalcode;
        $province = $this->province;
        $city = $this->city;
        $district = $this->district;
        $detail_info = $this->detail_info;
        $nationalcode = $this->nationalcode;
        $mobile = $this->mobile;
        $data = [
            'loginSession' => $loginSession,
            'username' => $username,
            'postalcode' => $postalcode,
            'province' => $province,
            'city' => $city,
            'district' => $district,
            'detail_info' => $detail_info,
            'nationalcode' => $nationalcode,
            'mobile' => $mobile
        ];
        $response = AddressLogic::createAddress($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Post(
     *     path="/address/delete",
     *     tags={"Address"},
     *     description="删除地址",
     *     operationId="deleteAddress",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="address_id",
     *         in="query",
     *         description="地址ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function deleteAddress()
    {
        $address_id = $this->address_id;
        $data = [
            'address_id' => $address_id
        ];
        $response = AddressLogic::deleteAddress($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Post(
     *     path="/address/update",
     *     tags={"Address"},
     *     description="更新地址",
     *     operationId="updateAddress",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="address_id",
     *         in="query",
     *         description="地址ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="username",
     *         in="query",
     *         description="收货人",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="postalcode",
     *         in="query",
     *         description="邮编",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="province",
     *         in="query",
     *         description="省",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="city",
     *         in="query",
     *         description="市",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="district",
     *         in="query",
     *         description="区",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="detail_info",
     *         in="query",
     *         description="详细地址",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="nationalcode",
     *         in="query",
     *         description="国家码",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="mobile",
     *         in="query",
     *         description="联系方式",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function updateAddress()
    {
        $address_id = $this->address_id;
        $username = $this->username;
        $postalcode = $this->postalcode;
        $province = $this->province;
        $city = $this->city;
        $district = $this->district;
        $detail_info = $this->detail_info;
        $nationalcode = $this->nationalcode;
        $mobile = $this->mobile;
        $data = [
            'address_id' => $address_id,
            'username' => $username,
            'postalcode' => $postalcode,
            'province' => $province,
            'city' => $city,
            'district' => $district,
            'detail_info' => $detail_info,
            'nationalcode' => $nationalcode,
            'mobile' => $mobile
        ];
        $response = AddressLogic::updateAddress($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Post(
     *     path="/address/changeDefault",
     *     tags={"Address"},
     *     description="改变默认地址",
     *     operationId="changeDefault",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="address_id",
     *         in="query",
     *         description="地址ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function changeDefault()
    {
        $address_id = $this->address_id;
        $loginSession = $this->loginSession;
        $data = [
            'address_id' => $address_id,
            'loginSession' => $loginSession
        ];
        $response = AddressLogic::changeDefault($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }
}